using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace SkypeStudio.CustomControl.Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //this.multiLineListBox1.Items.Add("asdasddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
            //this.multiLineListBox1.Items.Add("asdasdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddasdasdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddasdasdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddasdasddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");

        }

        private void button1_Click(object sender, EventArgs e)
        {

            //this.multiLineListBox1.Items.Add(this.textBox1.Text);

            //this.multiLineListBox2.Items.Add(this.textBox1.Text);
            //this.listBox1.Items.Add(this.textBox1.Text);

            this.richTextBox1.Text = this.richTextBox1.Text + this.textBox1.Text;
            this.htmlRichTextBox1.AddHTML(this.richTextBox1.Text);
        }

        private void multiLineListBox1_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            ListBox listbox = sender as ListBox;

            if (Site != null)
                return;
            if (e.Index > -1)
            {
                string s = listbox.Items[e.Index].ToString();
                SizeF sf = e.Graphics.MeasureString(s, Font, Width);
                int htex = (e.Index == 0) ? 15 : 10;
                //e.ItemHeight = (int)sf.Height + htex;
                e.ItemHeight = 500;

                e.ItemWidth = Width;

                Debug.WriteLine(string.Format("MeasureItem : e.Index : {0} ,e.Bounds.Width : {1}, e.Bounds.Height : {2}", e.Index, e.ItemWidth, e.ItemHeight));

            }
        }

        private void multiLineListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            ListBox listbox = sender as ListBox;

            //if (Site != null)
            //    return;
            if (e.Index > -1)
            {
                string s = listbox.Items[e.Index].ToString();

                SizeF sf = e.Graphics.MeasureString(s, Font, Width);

                Debug.WriteLine(string.Format("DrawItem : e.Index : {0} ,e.Bounds.Width : {1}, e.Bounds.Height : {2}", e.Index, e.Bounds.Width, e.Bounds.Height));


                //e.Bounds.Height = sf.Height;
                if ((e.State & DrawItemState.Focus) == 0)
                {
                    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Window), e.Bounds);
                    e.Graphics.DrawString(s, Font, new SolidBrush(SystemColors.WindowText),
                        e.Bounds);
                    e.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), e.Bounds);
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), e.Bounds);
                    e.Graphics.DrawString(s, Font, new SolidBrush(SystemColors.HighlightText),
                        e.Bounds);
                }
            }
        }

        private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            ListView listView = sender as ListView;

            //if (Site != null)
            //    return;
            if (e.ItemIndex > -1)
            {
                string s = listView.Items[e.ItemIndex].Text;

                SizeF sf = e.Graphics.MeasureString(s, Font, listView.Width);

                Debug.WriteLine(string.Format("DrawItem : e.Index : {0} ,e.Bounds.Width : {1}, e.Bounds.Height : {2}", e.ItemIndex, e.Bounds.Width, e.Bounds.Height));


                //e.Bounds.Height = sf.Height;
                if ((e.State & ListViewItemStates.Focused) == 0)
                {
                    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Window), e.Bounds);
                    e.Graphics.DrawString(s, Font, new SolidBrush(SystemColors.WindowText),
                        e.Bounds);
                    e.Graphics.DrawRectangle(new Pen(SystemColors.Highlight), e.Bounds);
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), e.Bounds);
                    e.Graphics.DrawString(s, Font, new SolidBrush(SystemColors.HighlightText),
                        e.Bounds);
                }
            }
        }
    }
}